package cn.edu.hqu.cst.android.XZY.Experiment2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

public class UC3 extends AppCompatActivity {

    private Button retenbutton3;
    //建立图片数组
    final ImageView[] imageView = new ImageView[5];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_u_c3);
        retenbutton3=findViewById(R.id.retbut3);
        retenbutton3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //返回至主界面
                Intent intent3 = new Intent(UC3.this,MainActivity.class);
                startActivity(intent3);
            }
        });
        //寻找图片
        imageView[0]=(ImageView) findViewById(R.id.img1);
        imageView[1]=(ImageView) findViewById(R.id.img2);
        imageView[2]=(ImageView) findViewById(R.id.img3);
        imageView[3]=(ImageView) findViewById(R.id.img4);
        imageView[4]=(ImageView) findViewById(R.id.img5);
        //设置可见
        for(ImageView a:imageView)
            a.setVisibility(View.INVISIBLE);
        final Handler handler=new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                if(msg.what==0x123)
                {
                    int i;
                    for(i=0;i<5;i++)
                        if(imageView[i].getVisibility()==View.VISIBLE)
                        {
                            imageView[i].setVisibility(View.INVISIBLE);
                            break;
                        }
                    if(i<4)
                        imageView[i+1].setVisibility(View.VISIBLE);
                    else
                        imageView[0].setVisibility(View.VISIBLE);
                }
                super.handleMessage(msg);
            }
        };
        new Timer().schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                handler.sendEmptyMessage(0x123);
            }
        },0,500);
    }
}